﻿using ExDUIR.NET.Declaration;
using ExDUIR.NET.Handle;
using System;


namespace ExDUIR.NET.Font
{
    public class ExFont
    {
        private readonly ExFontHandle _handle;
        public int Handle => _handle.Handle;
        public bool IsValid => _handle.IsInvalid;

        internal ExFont(ExFontHandle handle)
        {
            _handle = handle;
        }

        internal ExFont()
        {
            _handle = new ExFontHandle(ExAPI._font_create());
        }

        internal ExFont(string fontFace, int dwFontSize, int dwFontStyle)
        {
            _handle = new ExFontHandle(ExAPI._font_createfromfamily(fontFace, dwFontSize, dwFontStyle));
        }

        internal ExFont(string fontPath, int dwFontSize)
        {
            _handle = new ExFontHandle(ExAPI._font_createfromfile(fontPath, dwFontSize, 0));
        }

        internal ExFont(ref LogFont lpLogFont)
        {
            _handle = new ExFontHandle(ExAPI._font_createfromlogfont(ref lpLogFont));
        }

        public IntPtr Context
        {
            get
            {
                return ExAPI._font_getcontext(_handle.Handle);
            }
        }

        public LogFont LogFont
        {
            get
            {
                LogFont lpLogFont = new LogFont();
                ExAPI._font_getlogfont(_handle.Handle, ref lpLogFont);
                return lpLogFont;
            }
        }

        public void Dispose() => _handle.Dispose();
    }
}
